package cn.nawang.ebeim.test;

import cn.nawang.ebeim.test.constants.Config;
import cn.nawang.ebeim.test.db.DBHelper;
import cn.nawang.ebeim.test.service.DownloadService;
import cn.nawang.ebeim.test.service.TestData;
import cn.nawang.ebeim.test.service.UploadService;
import cn.nawang.ebeim.test.thread.ThreadPool;
import cn.nawang.ebeim.test.utils.SystemUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLException;
import java.util.Map;

/**
 * Created by GanJc on 2015-12-07 14:24
 */
public class AppMain {

    private static final Logger LOG = LoggerFactory.getLogger(AppMain.class);

    public static void main(String[] args) throws InterruptedException, IOException, SQLException {
        SystemUtil.initLog();
        new DBHelper().initDB();
//        args = new String[]{"upload"};
//        args = new String[]{"download"};
        if (args != null && args.length > 0) {
            String cmd = args[0];
            if ("upload".equalsIgnoreCase(cmd)) {
                ThreadPool.startUploadThread();
                for (String rootDir : Config.dsDirList) {
                    new UploadService(rootDir).upload();
                }
            } else if ("download".equalsIgnoreCase(cmd)) {
                ThreadPool.startDownloadThread();
                new DownloadService().download();
            } else {
                LOG.info("操作指令输入有误,请重试 [ download|upload ]");
            }
        } else {
            LOG.info("请输入操作指令 [ download|upload ]");
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true){
            LOG.info(args[0] + "测试报告:\n" + TestData.printResult());
            LOG.info("输入 q 退出程序!");
            String line = reader.readLine();
            if("q".equalsIgnoreCase(line)){
                System.exit(0);
            }
        }
    }



}
